﻿unit AddrFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, JvFormPlacement, JvComponentBase, JvAppStorage,
  cxGridExportLink,
  dxRibbonForm,
  DBGridEhImpExp,
  JvAppIniStorage, JvXPBar, JvExControls, JvXPCore, JvXPContainer, GridsEh,
  DBGridEh, ComCtrls, JvExComCtrls, JvComCtrls, ExtCtrls, JvExExtCtrls,
  JvExtComponent, JvSplit, DB, JvXPButtons, Grids, DBGrids, FIBSQLMonitor,
  StdCtrls, cxStyles, dxSkinsCore, dxSkinMcSkin, dxSkinSeven,
  dxSkinscxPCPainter, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGrid, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGridDBTableView,
  cxDBExtLookupComboBox, dxSkinsdxRibbonPainter, dxRibbon, JvDialogs,
  cxLookAndFeels, cxLookAndFeelPainters, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver;

type
  TAddrForm = class(Tdxcustomribbonform)
    JvAppIniFileStorage1: TJvAppIniFileStorage;
    Storage: TJvFormStorage;
    PageControl: TJvPageControl;
    TabSheet1: TTabSheet;
    StreetGrid: TDBGridEh;
    StreetDS: TDataSource;
    TabSheet2: TTabSheet;
    ZoneGrid: TDBGridEh;
    ZoneDS: TDataSource;
    TabSheet3: TTabSheet;
    TypeFlatDS: TDataSource;
    TypeFlatGrid: TDBGridEh;
    TabSheet4: TTabSheet;
    VidFlatDS: TDataSource;
    VidFlatGrid: TDBGridEh;
    Panel1: TPanel;
    JvXPBar1: TJvXPBar;
    TabSheet5: TTabSheet;
    AddrDS: TDataSource;
    AddrGrid: TDBGridEh;
    ExportExcel: TJvXPBar;
    ViewRepository1: TcxGridViewRepository;
    vb: TcxGridDBBandedTableView;
    clSTATE: TcxGridDBBandedColumn;
    clCODE: TcxGridDBBandedColumn;
    clNAME: TcxGridDBBandedColumn;
    clZONE: TcxGridDBBandedColumn;
    clZONE_NAME: TcxGridDBBandedColumn;
    clSTREET: TcxGridDBBandedColumn;
    clSTREET_NAME: TcxGridDBBandedColumn;
    clHOUSE: TcxGridDBBandedColumn;
    clFLAT: TcxGridDBBandedColumn;
    clVIDFLAT: TcxGridDBBandedColumn;
    clVIDFLAT_NAME: TcxGridDBBandedColumn;
    RibbonTab1: TdxRibbonTab;
    Ribbon: TdxRibbon;
    dlg1: TJvSaveDialog;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure ClickXPButton(Sender: TObject);
    procedure ExportExcelClick(Sender: TObject);
  private
    function GetActiveGrid: TDBGridEh;
  public
    { Public declarations }
  end;


var
  AddrForm: TAddrForm;

implementation
 uses  cmUtils, DModule, SetGridEh;

{$R *.dfm}

//=============================================================================
procedure TAddrForm.ClickXPButton(Sender: TObject);
begin
 PageControl.ActivePageIndex:=TJvXPBarItem(Sender).Tag;
end;

procedure TAddrForm.ExportExcelClick(Sender: TObject);
begin
  //SaveAsExcel(GetActiveGrid, nil, '');
 if dlg1.Execute then
 SaveDBGridEhToExportFile(TDBGridEhExportAsXLS,
                          GetActiveGrid,dlg1.FileName+'.xls',true);
end;

procedure TAddrForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 RemoveBtn(Name);
 SaveGrids(Self);
 Action:=caFree;
end;

procedure TAddrForm.FormCreate(Sender: TObject);
begin
 vb.DataController.DataSource:=nil;
 dm1.FDS_Street.CloseOpen(false);
 dm1.FDS_Zone.CloseOpen(false);
 dm1.FDS_TypeFlat.CloseOpen(false);
 dm1.FDS_VidFlat.CloseOpen(false);
 dm1.FDS_Addr.CloseOpen(false);
 AddButton(self);
 InitGrids(Self);
 //vb.DataController.DataSource:=AddrDS;
 PageControl.ActivePageIndex:=4;
end;

function TAddrForm.GetActiveGrid: TDBGridEh;
begin
 case PageControl.ActivePageIndex of
  0: Result:=StreetGrid;
  1: Result:=ZoneGrid;
  2: Result:=TypeFlatGrid;
  3: Result:=VidFlatGrid;
  else Result:=AddrGrid;
 end;
end;


end.
